﻿Public Class frmImportChuNha
    Dim dt As DataTable = New DataTable()

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        openFile.Filter = "Import du lieu tu file (*.xls)|*.xls | Hoặc file (*.xlsx)|*.xlsx"
        If Not IsNothing(openFile.ShowDialog() = DialogResult.OK) Then
            Try
                Dim path As String = openFile.FileName
                dt = Import.Get_ChuNha_FromExcel(path)
                gvDSChuNha.DataSource = dt
            Catch ex As Exception
                MessageBox.Show("Phát hiện lỗi !!\n " + ex.Message, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub btnImportChuNha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportChuNha.Click
        For i As Integer = 0 To dt.Rows.Count - 1
            Dim cn As NguoiDangDTO = New NguoiDangDTO()
            Dim macuoi As String = NguoiDangBUS.LayMa_ND_Cuoi()

            cn.strMaNguoiDang = NguoiDangBUS.TinhMaNguoiDang(macuoi)

            cn.strHoTen = dt.Rows(i)(1).ToString()
            cn.strDiaChi = dt.Rows(i)(2).ToString()
            cn.strDienThoai = dt.Rows(i)(3).ToString()
            cn.strEmail = dt.Rows(i)(4).ToString()
            cn.isTamXoa = dt.Rows(i)(5).ToString()
            Try
                NguoiDangBUS.Insert(cn)
            Catch ex As Exception
                MessageBox.Show("Phát hiện lỗi !!\n " + ex.Message, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        Next
        MessageBox.Show("Nhận dữ liệu thành công !", "THÔNG BÁO")
    End Sub
End Class